import os

from pub_func import get_list_file

list_file = get_list_file('./')
list_file.sort()
for filename in list_file:
    with open(filename, 'r', encoding='utf8') as f: 
        list_content = f.readlines()
        for content in list_content[1:]:
            sf = content.split(',')[0]
            xzys = content.split(',')[1]
            ljys = content.split(',')[2]
            xzqz = content.split(',')[3]
            ljqz = content.split(',')[4]
            xzsw = content.split(',')[5]
            ljsw = content.split(',')[6]
            new_filename = sf + '.csv'
            content =  content =  str(filename[2:10]) + ',' + str(xzys) + ',' + str(ljys) + ','+ str(xzqz) + ','+ str(ljqz) + ','+ str(xzsw) + ',' + str(ljsw)
            title = '时间' + ',' + '新增疑似' + ',' + '累计疑似' + ','+ '新增确诊' + ',' + '累计确诊' + ','+ '新增死亡' + ','+ '累计死亡' +  '\n'
            if not os.path.exists(new_filename):
                with open(new_filename, 'a') as f:
                    f.write(title)
            else:
                with open(new_filename, 'a') as f:
                    f.write(content)